package com.pvdnc.rimetmodule;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.util.Log;

import java.lang.reflect.Method;

import andhook.lib.xposed.XC_MethodHook;
import andhook.lib.xposed.XposedBridge;

public class RimetModule {
    private static final String TAG=RimetModule.class.getSimpleName();

    private static Class<?> loadAppClass(Application app,String name) throws ClassNotFoundException {
        ClassLoader cl= app.getClassLoader();
        return cl.loadClass(name);
    }

    public static void onLoad(final Application app){
        Log.d(TAG,"in app:"+app);
        try {
            System.setProperty("riru.property_env_loaded","true");

            Class<?> bridgeClass=XposedBridge.class;
            Log.d(TAG,"bridge class:"+bridgeClass);
            Method method= NotificationManager.class.getDeclaredMethod("notify", String.class, int.class, Notification.class);
            XposedBridge.hookMethod(method,new XC_MethodHook(){
                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    super.beforeHookedMethod(param);
                    Log.d(TAG,"invoke before notify");
                    try{
                        throw new RuntimeException("get stack trace");
                    }catch (RuntimeException e){
                        Log.w(TAG,"notify stack trace:\n\t");
                        e.printStackTrace();
                    }
                }
            });
            Log.d(TAG,"finish hooking notify");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
